Skip to content

Instantly share code, notes, and snippets.

View jamesmorgan's full-sized avatar

James Morgan jamesmorgan

View GitHub Profile
@ptomato
ptomato / debug.js
Created November 18, 2013 05:39
GJS debugger
const GLib = imports.gi.GLib;
const Lang = imports.lang;
const System = imports.system;
let _breakpoints = 0;
function _getCurrentStack() {
try {
throw new Error();
} catch (e) {
@katowulf
katowulf / normalize_record.js
Last active January 5, 2018 00:08
Normalize a "post" record by adding "user" data from another Firebase path in AngularFire
app.factory('NormalizedPosts', function($firebaseArray, userCache) {
var PostsWithUsers = $firebaseArray.$extend({
// override $$added to include users
$$added: function(snap) {
// call the super method
var record = $firebaseArray.prototype.$$added.call(this, snap);
userCache.$load( record.user ).$loaded(function( userData ) {
record.userData = userData;
});
@Integralist
Integralist / 1. WindowMock.js
Last active November 9, 2020 20:51
Mocking the `window` object in JavaScript unit tests
define([
'module/bootstrap', // this is jQuery and PubSub libs
], function (lib) {
var windowMock = {
resizeSet: false, // set within the fake `lib` object below
createFakeWindow: function(width, height) {
return {
document: {
documentElement: {
@andyyou
andyyou / iterm2-solarized.md
Created September 30, 2015 13:58 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + oh my zsh + solarized + Meslo powerline font (OSX)

Solarized

@z0r0z
z0r0z / Multisig.sol
Created December 25, 2021 23:40
Simple gas-optimized multi-signature contract with crowdsourced enhancements.
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.4;
/// @notice Simple gas-optimized multi-signature contract.
contract Multisig {
event Propose(address indexed proposer, uint256 indexed proposal);
event Sign(address indexed signer, uint256 indexed proposal);
event Execute(uint256 indexed proposal);
@z0r0z
z0r0z / Multisig.sol
Last active March 9, 2022 01:50
Simple gas-optimized multi-signature contract.
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.4;
/// @notice Simple gas-optimized multi-signature contract.
contract Multisig {
event Propose(address indexed proposer, uint256 indexed proposal);
event Sign(address indexed signer, uint256 indexed proposal);
event Execute(uint256 indexed proposal);
error NotSigner();
@IamAdiSri
IamAdiSri / Python3, Pip3, Virtualenv and Virtualenvwrapper Setup
Last active May 9, 2022 22:08 — forked from evansneath/Python3 Virtualenv Setup
Setting up and using Python3, Pip3, Virtualenv (for Python3) and Virtualenvwrapper (for Python3)
First install pip for Python2. Download the get-pip.py file from https://bootstrap.pypa.io/get-pip.py
$ cd <download location>
$ sudo -H python ./get-pip.py
Installing pip also installs Python3
To run Python3
$ python3
Install pip3 by just executing the same file as in the step above, but this time using Python3
$ sudo -H python3 ./get-pip.py
const fs = require("fs");
const solc = require('solc')
let Web3 = require('web3');
let web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
var input = {
'strings.sol': fs.readFileSync('strings.sol', 'utf8'),
'StringLib.sol': fs.readFileSync('StringLib.sol', 'utf8'),
@buzztaiki
buzztaiki / gjs-io-sample.js
Created December 16, 2011 20:18
gjs-io-sample.js
const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;
let [res, out, err, status] = GLib.spawn_command_line_sync('ls -la');
print(out);
let [res, out] = GLib.spawn_command_line_sync('ls -la');
print(out);
let [res, out] = GLib.spawn_sync(null, ['/bin/ls', '-la'], null, 0, null);
@alexvandesande
alexvandesande / Random generator
Last active December 23, 2022 09:10
A very simple random generator. A miner can influence the number by not publishing a block with an unwanted outcome, and forfeiting the 5 block reward.
contract random {
/* Generates a random number from 0 to 100 based on the last block hash */
function randomGen(uint seed) constant returns (uint randomNumber) {
return(uint(sha3(block.blockhash(block.number-1), seed ))%100);
}
/* generates a number from 0 to 2^n based on the last n blocks */
function multiBlockRandomGen(uint seed, uint size) constant returns (uint randomNumber) {
uint n = 0;
for (uint i = 0; i < size; i++){