This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIT licensed. | |
use std::net::TcpStream; | |
use std::io::{Read, Write}; | |
use std::sync::mpsc::channel; | |
use std::thread; | |
fn main() { | |
let mut stream = TcpStream::connect("127.0.0.1:7496").expect("connect"); | |
stream.set_nodelay(true).expect("nodelay"); // Because we're wannabe HFT traders. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); // dgram is UDP | |
// Listen for responses | |
function listen(port) { | |
var server = dgram.createSocket("udp4"); | |
server.on("message", function (msg, rinfo) { | |
console.log("server got: " + msg + " from " + rinfo.address + ":" + rinfo.port); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.mycompanyname.mydepartment.mytaskname</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/myuser/Dashboard/mytask.sh</string> | |
</array> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For detecting taps outside of the alert view | |
-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer { | |
CGPoint p = [gestureRecognizer locationInView:self]; | |
if (p.y < 0) { // They tapped outside | |
[self dismissWithClickedButtonIndex:0 animated:YES]; | |
} | |
} | |
-(void) showFromTabBar:(UITabBar *)view { | |
[super showFromTabBar:view]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
// Firstly, we want to figure out who is the currently visible view controller. | |
// There are 4 possibilities here: | |
// 1- They could be a non-nav controller, with a visible tab (ie not under the 'more' tab) | |
// Simple: self.selectedViewController | |
// 2- They could be a nav controller, with a visible tab (ie not under the 'more' tab) | |
// Get it's visible view: self.selectedViewController.visibleViewController | |
// 3- They could be a non-nav controller, under the 'more' tab | |
// Simple: self.selectedViewController | |
// 4- They could be a nav controller, under the 'more' tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
minissdpdSocket = '/var/run/minissdpd.sock' # The socket for talking to minissdpd | |
# Sends a message to the given socket | |
def sendMessage(message): | |
s = socket.socket(socket.AF_UNIX) | |
s.settimeout(1) # 1 second timeout, after all it should be instant because its local | |
s.connect(minissdpdSocket) | |
s.send(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#define DEVICE (0x53) // ADXL345 device address when the SDO pin (12) is grounded | |
void setup() | |
{ | |
Wire.begin(); // join i2c bus (address optional for master) | |
Serial.begin(115200); // start serial for output | |
// Wake up the accelerometer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log ('Input some code:'); | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.once('data', function (someCode) { | |
process.stdin.pause(); | |
console.log ('Code: ' + someCode); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// Simple observable property | |
// Careful: Not thread safe! You should use this only from the main thread, or modify to | |
// have locks. | |
class Property<T> { | |
private var _value: T | |
var value: T { | |
get { return _value } | |
set { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <netinet/in.h> | |
#include <sys/socket.h> | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
- (void)sendBroadcastPacket { | |
// Open a socket | |
int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | |
if (sd<=0) { | |
NSLog(@"Error: Could not open socket"); |
NewerOlder