Skip to content

Instantly share code, notes, and snippets.

@coybit
coybit / TestCombinePublisher.swift
Created June 5, 2020 23:33
Two simple Combine Operators to test the sequence of values a Combine Publisher emits.
// Operators
extension Publisher where Self.Output: Equatable {
public func test(equalTo expectation: [Self.Output]) -> AnyCancellable {
self
.assertNoFailure()
.reduce([Self.Output](), { $0 + [$1] })
.sink() { assert($0 == expectation) }
}
$('.transactionAmount').map(function(x,y) { return $(y).text().replace('€','').replace(',','.'); }).map((x,y) => parseFloat(y)).toArray().reduce(function(x,y) { return x + y}, 0)
find . -name \* | awk '{if(length($1)>100) { print length($1),$1 } }' | sort
@coybit
coybit / magpi.sh
Last active March 17, 2022 06:28 — forked from omarowns/magpi.sh
Bash script to download all issues of The MagPi.
#!/bin/bash
#
# Creates a directory named "magpi" on your home folder and all issues are downloaded there.
# It also checks if you already have some of the issues and skips them from downloading.
# Use argument: --log OFF to disable logging. It is there because I have this script on my crontab and I needed to monitor if it running properly. For enabling logging do:
# $ sudo touch /var/log/magpi.log
# $ sudo chmod 666 /var/log/magpi.log
# That's it.
#
# Command execution is:
@coybit
coybit / Everyauth - Linkedin - User's email
Created April 13, 2014 11:23
Everyauth - Fetching user's email address when authenticating with Linkedin
everyauth.linkedin
.consumerKey(LINKEDIN_CONSUMER_KEY)
.consumerSecret(LINKEDIN_CONSUMER_SECRET)
.fetchOAuthUser(function (accessToken, accessTokenSecret, params) { // This method is override because we need to get extra info from user profile
var promise = this.Promise();
this.oauth.get(this.apiHost() + '/people/~:(id,first-name,last-name,emailAddress,headline,location:(name,country:(code)),industry,num-connections,num-connections-capped,summary,specialties,proposal-comments,associations,honors,interests,positions,publications,patents,languages,skills,certifications,educations,three-current-positions,three-past-positions,num-recommenders,recommendations-received,phone-numbers,im-accounts,twitter-accounts,date-of-birth,main-address,member-url-resources,picture-url,site-standard-profile-request:(url),api-standard-profile-request:(url,headers),public-profile-url)', accessToken, accessTokenSecret, function (err, data, res) {
if (err) {
err.extra = {data: da
@coybit
coybit / Audio Streaming
Created March 13, 2014 12:37
Downloading audio file and playing it ( A simple replacement for short audio streaming )
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *mp3URL = [NSURL URLWithString:@"http://zhangmenshiting.baidu.com/data2/music/44799433/4479927746800128.mp3?xcode=dbff90a141d5d136fdc7275fdc3fae126077a44adc974ad8"];
NSData *data = [NSData dataWithContentsOfURL:mp3URL];
self.audioPlayer = [[AVAudioPlayer alloc] initWithData:data error:NULL];
[self.audioPlayer play];
});
#define $(...) ((NSString *)[[NSArray arrayWithObjects:__VA_ARGS__, nil] componentsJoinedByString:@""])
/*
* Example
*/
NSString *string = $(@"Hello", @" ", @"World!", @"\n", @"1 + 2 = ", @(1+2));
.parent {
position: relative;
}
.child {
position: absolute;
display: block;
left: 0;
right: 0;
@coybit
coybit / jPlayer
Created February 16, 2014 09:51
A sample code for using jPlayer inside a web page as video/audio player
<html>
<head>
<link type="text/css" href="http://jplayer.org/latest/skin/blue.monday/jplayer.blue.monday.css" rel="stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://jplayer.org/latest/js/jquery.jplayer.min.js"></script>